//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by 张子国 on 15/11/8.
//  Copyright © 2015年 张子国. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    //实现 tabbarButton 的监听方法
    @objc func composeDidClick () {
        let compose = ComposeViewController()
        let nav = UINavigationController(rootViewController: compose)
        presentViewController(nav, animated: true, completion: nil)
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        addChildViewController()
        
        //kvc赋值tabbar的frame （get）
        let mainT = MainTabbar()
        
        setValue(mainT, forKey: "tabBar")
        addChildViewController()
        
        print(tabBar.classForCoder)
        
        //设置点击事件
        
        mainT.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents:.TouchUpInside)
    }
    private func addChildViewController() {
        addChildViewController(HomeViewController() ,title : "首页", imageName : "tabbar_home" )
        addChildViewController(MessageViewController() ,title : "消息", imageName : "tabbar_message_center" )
        addChildViewController(DiscoverViewController() ,title : "发现", imageName : "tabbar_discover" )
        addChildViewController(profileViewController(),title : "我", imageName : "tabbar_profile")
        
    }

    //重载
    private func addChildViewController(vc: UIViewController, title : String, imageName : String) {
        //self.tabBar.tintColor = UIColor.orangeColor()
        
//      let nav = UINavigationController (rootViewController: vc)
        
        let nav = BaseNavViewController(rootViewController : vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
    }
   
}
